﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Platform.Data;
using Platform.Menu;
using Platform.Permission;
using Web.Class;
using Entity;
using BLL;

namespace Web
{
    public partial class DefaultN : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.hdCollection.Set("uid",LoginInfo.CurrentUser.UserID);
                this.hdCollection.Set("wtype",BusinessTool.WType);
                if (null == HttpContext.Current.Session["_UserName"])
                {
                    HttpContext.Current.Session["_UserName"] = Platform.Permission.LoginHelper.Name; 
                } 
            }
        }

        protected void btnLogOut_Click(object sender, EventArgs e)
        {
            string rsno="-1";
            string rsmsg="";
            new BLL.Access.SpHelper().P_LOGIN(LoginHelper.UserID, 2,out rsno, out rsmsg);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "logout()",true);
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            if (e.Parameter == "loglink")
            {
                try
                {
                    string rsno = "-1";
                    string rsmsg = "";
                    //判断session是否失效,失效则自动记录登出
                    if (LoginInfo.CurrentUser.UserID == 0)
                    {
                        new BLL.Access.SpHelper().P_LOGIN(LoginHelper.UserID,2, out rsno, out rsmsg);
                        cr.IsSuccess = true;
                        cr.IsAlertMsg = false;
                        e.Result = cr.ToString();
                        return;
                    }                    
                    new BLL.Access.SpHelper().P_LOGIN(LoginHelper.UserID, 3, out rsno, out rsmsg);
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = false;
                    e.Result = cr.ToString();
                }
                catch (Exception ex)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = ex.Message;
                    e.Result = cr.ToString();
                }
               
            }

        }
    }
}